<script setup>
import pageCom from '@/components/pagecontainer.vue'
import channeldialog from '@/components/channeldialog.vue'
import { getChannelService, delCannelService } from "@/api/atricle"
import { onMounted, ref } from 'vue'
const title = ref('文章分类')
const channelList = ref()
const loading = ref(false)
const chlog = ref()
const getList = async () => {
  loading.value = true
  const res = await getChannelService()

  channelList.value = res.data.data
  loading.value = false
}
getList()
const onEidt = (row) => {
  chlog.value.open(row)
}
const onDel = async (row) => {
  await ElMessageBox.confirm('你确定要删除吗?', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  await delCannelService(row.id)
  ElMessage.success('删除成功')
  getList()
}
const addFn = () => {
  chlog.value.open()
}
const onsu = () => {
  getList()
}
</script>

<template>
  <pageCom :title="title">
    <template #extra>
      <div>
        <el-button class="primary" @click="addFn">添加分类</el-button>
      </div>
    </template>

    <el-table v-loading="loading" :data="channelList" style="width: 100%">
      <el-table-column type="index" label="序号" width="100" />
      <el-table-column prop="cate_name" label="分类名称" />
      <el-table-column prop="cate_alias" label="分类别名" />
      <el-table-column label="操作" width="100">
        <template #default="{ row, $index }">
          <div>
            <el-button plain circle icon="Edit" @click="onEidt(row, $index)"></el-button>
            <el-button plain circle icon="Delete" @click="onDel(row, $index)"></el-button>
          </div>
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="莫得数据显示哦"></el-empty>
      </template>
    </el-table>
    <channeldialog ref="chlog" @success="onsu"></channeldialog>
  </pageCom>
</template>

<style lang="scss" scoped></style>